/**
 * 
 */
package com.bolbachchan.blog.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author Chaitanya
 * 
 */
@Entity
@Table(name = "USER_DETAILS")
@NamedQueries({
	@NamedQuery(name = "getUserDetailsByUsername", query = "FROM UserDetails WHERE username= :username"),
	@NamedQuery(name = "getUserDetailsById", query = "FROM UserDetails WHERE objId= :objId"),
	@NamedQuery(name = "updateLastLogin", query = "UPDATE UserDetails SET lastLogin= :lastLogin WHERE username= :username") })
public class UserDetails implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -7024777910248698143L;

    private int objId;
    private String username;
    private String password;
    private String firstName;
    private String lastName;
    private String addressLine1;
    private String addressLine2;
    private String city;
    private String state;
    private String country;
    private String phone;
    private Timestamp dateRegistered;
    private Timestamp lastLogin;

    private Set<SecurityAnswers> securityAnswers = new HashSet<SecurityAnswers>();
    private Set<Posts> posts = new HashSet<Posts>();
    private Set<Comments> comments = new HashSet<Comments>();

    /**
     * @return the objId
     */
    @Id
    @Column(name = "OBJ_ID")
    public int getObjId() {
	return objId;
    }

    /**
     * @param objId
     *            the objId to set
     */
    public void setObjId(int objId) {
	this.objId = objId;
    }

    /**
     * @return the username
     */
    @Column(name = "USERNAME", unique = true)
    public String getUsername() {
	return username;
    }

    /**
     * @param username
     *            the username to set
     */
    public void setUsername(String username) {
	this.username = username;
    }

    /**
     * @return the password
     */
    @Column(name = "PASSWORD")
    public String getPassword() {
	return password;
    }

    /**
     * @param password
     *            the password to set
     */
    public void setPassword(String password) {
	this.password = password;
    }

    /**
     * @return the firstName
     */
    @Column(name = "FIRST_NAME")
    public String getFirstName() {
	return firstName;
    }

    /**
     * @param firstName
     *            the firstName to set
     */
    public void setFirstName(String firstName) {
	this.firstName = firstName;
    }

    /**
     * @return the lastName
     */
    @Column(name = "LAST_NAME")
    public String getLastName() {
	return lastName;
    }

    /**
     * @param lastName
     *            the lastName to set
     */
    public void setLastName(String lastName) {
	this.lastName = lastName;
    }

    /**
     * @return the addressLine1
     */
    @Column(name = "ADDRESS_LINE1")
    public String getAddressLine1() {
	return addressLine1;
    }

    /**
     * @param addressLine1
     *            the addressLine1 to set
     */
    public void setAddressLine1(String addressLine1) {
	this.addressLine1 = addressLine1;
    }

    /**
     * @return the addressLine2
     */
    @Column(name = "ADDRESS_LINE2")
    public String getAddressLine2() {
	return addressLine2;
    }

    /**
     * @param addressLine2
     *            the addressLine2 to set
     */
    public void setAddressLine2(String addressLine2) {
	this.addressLine2 = addressLine2;
    }

    /**
     * @return the city
     */
    @Column(name = "CITY")
    public String getCity() {
	return city;
    }

    /**
     * @param city
     *            the city to set
     */
    public void setCity(String city) {
	this.city = city;
    }

    /**
     * @return the state
     */
    @Column(name = "STATE")
    public String getState() {
	return state;
    }

    /**
     * @param state
     *            the state to set
     */
    public void setState(String state) {
	this.state = state;
    }

    /**
     * @return the country
     */
    @Column(name = "COUNTRY")
    public String getCountry() {
	return country;
    }

    /**
     * @param country
     *            the country to set
     */
    public void setCountry(String country) {
	this.country = country;
    }

    /**
     * @return the phone
     */
    @Column(name = "PHONE")
    public String getPhone() {
	return phone;
    }

    /**
     * @param phone
     *            the phone to set
     */
    public void setPhone(String phone) {
	this.phone = phone;
    }

    /**
     * @return the dateRegistered
     */
    @Column(name = "DATE_REGISTERED")
    public Timestamp getDateRegistered() {
	return dateRegistered;
    }

    /**
     * @param dateRegistered
     *            the dateRegistered to set
     */
    public void setDateRegistered(Timestamp dateRegistered) {
	this.dateRegistered = dateRegistered;
    }

    /**
     * @return the lastLogin
     */
    @Column(name = "LAST_LOGIN")
    public Timestamp getLastLogin() {
	return lastLogin;
    }

    /**
     * @param lastLogin
     *            the lastLogin to set
     */
    public void setLastLogin(Timestamp lastLogin) {
	this.lastLogin = lastLogin;
    }

    /**
     * @return the securityAnswers
     */
    @OneToMany(mappedBy = "userDetails", fetch = FetchType.EAGER)
    public Set<SecurityAnswers> getSecurityAnswers() {
	return securityAnswers;
    }

    /**
     * @param securityAnswers
     *            the securityAnswers to set
     */
    public void setSecurityAnswers(Set<SecurityAnswers> securityAnswers) {
	this.securityAnswers = securityAnswers;
    }

    /**
     * @return the posts
     */
    @OneToMany(mappedBy = "userDetails", fetch = FetchType.EAGER)
    public Set<Posts> getPosts() {
	return posts;
    }

    /**
     * @param posts
     *            the posts to set
     */
    public void setPosts(Set<Posts> posts) {
	this.posts = posts;
    }

    /**
     * @return the comments
     */
    @OneToMany(mappedBy = "userDetails", fetch = FetchType.EAGER)
    public Set<Comments> getComments() {
	return comments;
    }

    /**
     * @param comments
     *            the comments to set
     */
    public void setComments(Set<Comments> comments) {
	this.comments = comments;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     * @Override public int hashCode() { final int prime = 31; int result = 1;
     * result = prime * result + ((addressLine1 == null) ? 0 :
     * addressLine1.hashCode()); result = prime * result + ((addressLine2 ==
     * null) ? 0 : addressLine2.hashCode()); result = prime * result + ((city ==
     * null) ? 0 : city.hashCode()); result = prime * result + ((comments ==
     * null) ? 0 : comments.hashCode()); result = prime * result + ((country ==
     * null) ? 0 : country.hashCode()); result = prime * result +
     * ((dateRegistered == null) ? 0 : dateRegistered.hashCode()); result =
     * prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result
     * = prime * result + ((lastLogin == null) ? 0 : lastLogin.hashCode());
     * result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
     * result = prime * result + objId; result = prime * result + ((password ==
     * null) ? 0 : password.hashCode()); result = prime * result + ((phone ==
     * null) ? 0 : phone.hashCode()); result = prime * result + ((posts == null)
     * ? 0 : posts.hashCode()); result = prime * result + ((securityAnswers ==
     * null) ? 0 : securityAnswers.hashCode()); result = prime * result +
     * ((state == null) ? 0 : state.hashCode()); result = prime * result +
     * ((username == null) ? 0 : username.hashCode()); return result; }
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     * @Override public boolean equals(Object obj) { if (this == obj) return
     * true; if (obj == null) return false; if (getClass() != obj.getClass())
     * return false; UserDetails other = (UserDetails) obj; if (addressLine1 ==
     * null) { if (other.addressLine1 != null) return false; } else if
     * (!addressLine1.equals(other.addressLine1)) return false; if (addressLine2
     * == null) { if (other.addressLine2 != null) return false; } else if
     * (!addressLine2.equals(other.addressLine2)) return false; if (city ==
     * null) { if (other.city != null) return false; } else if
     * (!city.equals(other.city)) return false; if (comments == null) { if
     * (other.comments != null) return false; } else if
     * (!comments.equals(other.comments)) return false; if (country == null) {
     * if (other.country != null) return false; } else if
     * (!country.equals(other.country)) return false; if (dateRegistered ==
     * null) { if (other.dateRegistered != null) return false; } else if
     * (!dateRegistered.equals(other.dateRegistered)) return false; if
     * (firstName == null) { if (other.firstName != null) return false; } else
     * if (!firstName.equals(other.firstName)) return false; if (lastLogin ==
     * null) { if (other.lastLogin != null) return false; } else if
     * (!lastLogin.equals(other.lastLogin)) return false; if (lastName == null)
     * { if (other.lastName != null) return false; } else if
     * (!lastName.equals(other.lastName)) return false; if (objId !=
     * other.objId) return false; if (password == null) { if (other.password !=
     * null) return false; } else if (!password.equals(other.password)) return
     * false; if (phone == null) { if (other.phone != null) return false; } else
     * if (!phone.equals(other.phone)) return false; if (posts == null) { if
     * (other.posts != null) return false; } else if
     * (!posts.equals(other.posts)) return false; if (securityAnswers == null) {
     * if (other.securityAnswers != null) return false; } else if
     * (!securityAnswers.equals(other.securityAnswers)) return false; if (state
     * == null) { if (other.state != null) return false; } else if
     * (!state.equals(other.state)) return false; if (username == null) { if
     * (other.username != null) return false; } else if
     * (!username.equals(other.username)) return false; return true; }
     */

    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
	return "UserDetails [objId=" + objId + ", username=" + username + ", password=" + password + ", firstName="
		+ firstName + ", lastName=" + lastName + ", addressLine1=" + addressLine1 + ", addressLine2="
		+ addressLine2 + ", city=" + city + ", state=" + state + ", country=" + country + ", phone=" + phone
		+ ", dateRegistered=" + dateRegistered + ", lastLogin=" + lastLogin + ", securityAnswers="
		+ securityAnswers + ", posts=" + posts + ", comments=" + comments + "]";
    }
}
